package com.zhongxi.guoyuan.OffLineShop.Adapter;

import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import com.zhongxi.guoyuan.OffLineShop.Model.PayMentList;
import com.zhongxi.guoyuan.R;
import com.zhongxi.guoyuan.utils.DataUtil;

import java.util.ArrayList;

/**
 * Created by Administrator on 2018/4/12.
 */

public class MentlistAdapter extends RecyclerView.Adapter<MentlistAdapter.MentViewHolder> {

    private ArrayList<PayMentList.MentList> data;

    public MentlistAdapter(ArrayList<PayMentList.MentList> data) {
        this.data = data;
    }

    @Override
    public MentViewHolder onCreateViewHolder(final ViewGroup parent, int viewType) {
        View mView = LayoutInflater.from(parent.getContext()).inflate(R.layout.item_mentlist, parent, false);
        return new MentViewHolder(mView);
    }

    @Override
    public void onBindViewHolder(final MentViewHolder holder, final int position) {
        PayMentList.MentList mMentList = data.get(position);
        holder.mTvTime.setText(mMentList.ctime);
        holder.mTvShouldPrice.setText("应付:  " + mMentList.shouldprice + " 元");
        holder.mTvTruePrice.setText("实付:  " + mMentList.payprice + " 元");
        holder.mTvHongdou.setText(mMentList.backcashnum + " 元");
        holder.mTvMeidou.setText(mMentList.backinnernum + " 美豆");
        holder.itemView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (onItemClickListener != null) {
                    onItemClickListener.onItemClickListener(holder.itemView, position);
                }
            }
        });
    }

    @Override
    public int getItemCount() {
        if (data != null && data.size() > 0) {
            return data.size();
        }
        return 0;
    }

    class MentViewHolder extends RecyclerView.ViewHolder {

        TextView mTvTime;
        TextView mTvShouldPrice;
        TextView mTvTruePrice;
        TextView mTvHongdou;
        TextView mTvMeidou;

        public MentViewHolder(View itemView) {
            super(itemView);
            mTvTime = (TextView) itemView.findViewById(R.id.tv_time);
            mTvShouldPrice = (TextView) itemView.findViewById(R.id.tv_shouldPrice);
            mTvTruePrice = (TextView) itemView.findViewById(R.id.tv_truePrice);
            mTvHongdou = (TextView) itemView.findViewById(R.id.tv_hongdou);
            mTvMeidou = (TextView) itemView.findViewById(R.id.tv_meidou);
        }
    }


    private OnItemClickListener onItemClickListener;

    public void setOnItemClickListener(OnItemClickListener onItemClickListener) {
        this.onItemClickListener = onItemClickListener;
    }

    public interface OnItemClickListener {
        void onItemClickListener(View view, int position);
    }
}
